
/* Replication for weighting. The results drom these codes are discussed in page 15 of the article */


use "C:\Users\ls42\Dropbox\google consumer surveys\Replication Materials\framing_10qn.dta", clear

/*we create a variable saidtoolittle where 1=respondents answer too little and 0=otherwise */
gen saidtoolittle=0
replace saidtoolittle=1 if Question3Answer=="Too Little"
replace saidtoolittle=. if Question3Answer=="Don't Know"


drop if age==7|gender==3 /* drop unknown values */

/* producing weight using inferred demographics */

gen age_tot=1410  if age==1
replace age_tot=1940  if age==2
replace age_tot=1880  if age==3
replace age_tot=1940  if age==4
replace age_tot=1600  if age==5
replace age_tot=1230  if age==6

gen gend_tot=4800  if gender==2
replace gend_tot=5200  if gender==1



drop if Question1Answer=="I prefer not to say"
drop if Question2Answer=="I prefer not to say"

gen old_wt=1

capture drop new_wt
survwgt rake old_wt,  ///
by(gender age) totvars(gend_tot age_tot)    ///
gen(new_wt)

/* Correlation between GCS' supplied weight and weights from inferred demographics*/

correlate Weight new_wt


/* producing weight using self-reported demographics */

capture drop age_tot2
gen age_tot2=1410  if Question1Answer=="18-24"
replace age_tot2=1940  if Question1Answer=="25-34"
replace age_tot2=1880  if Question1Answer=="35-44"
replace age_tot2=1940  if Question1Answer=="45-54"
replace age_tot2=1600  if Question1Answer=="55-64"
replace age_tot2=1230  if Question1Answer=="65+"

capture drop gend_tot2
gen gend_tot2=4800  if Question2Answer=="Male"
replace gend_tot2=5200  if Question2Answer=="Female"

capture drop new_wt2
survwgt rake old_wt,  ///
by(Question2Answer Question1Answer) totvars(gend_tot2 age_tot2)    ///
gen(new_wt2)

/* Correlation between GCS' supplied weight and weights from self-reported demographics*/

correlate new_wt new_wt2


/* Calculate treatment effect */

regress saidtoolittle group [pweight=new_wt] /* weighted treatment effect using inferred demographics*/

regress saidtoolittle group [pweight=new_wt2] /* weighted treatment effect using self-reported demographics*/

regress saidtoolittle group [pweight=Weight] /* weighted treatment effect using Google's provided weights */

regress saidtoolittle group /* un-weighted treatment effect */






















